﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entity;
using System.Data.SqlClient;
using System.Collections.ObjectModel;
using Helper;

namespace DAL
{
    public class EventDAL
    {
        //-------------------EventSearchTitleById_ce-------------------
        public List<objEvent> EventSearchTitleById_ce(int idCe)
        {
            
            List<objEvent> lst = new List<objEvent>();

            objEvent obj = null;

            Collection<SqlParameter> parameterList = new Collection<SqlParameter>();

            parameterList.Add(new SqlParameter("@id_ce", idCe));


            SqlDataReader dr = SQLHelper.ExecuteReader("spEventSearchTitleById_ce", parameterList);
            while (dr.Read())
            {
                obj = new objEvent();

                obj.Id = int.Parse(dr["id"].ToString());

                obj.Title = dr["title"].ToString();


                lst.Add(obj);
            }
            dr.Close();
            return lst;

        }

        //-------------------EventSearchById-------------------
        public List<objEvent> EventSearchById(int id)
        {

            List<objEvent> lst = new List<objEvent>();

            objEvent obj = null;

            Collection<SqlParameter> parameterList = new Collection<SqlParameter>();

            parameterList.Add(new SqlParameter("@id", id));


            SqlDataReader dr = SQLHelper.ExecuteReader("spEventSearchById", parameterList);
            while (dr.Read())
            {
                obj = new objEvent();

                obj.Id = int.Parse(dr["id"].ToString());

                obj.Title = dr["title"].ToString();


                lst.Add(obj);
            }
            dr.Close();
            return lst;
        }

        //---------------------EventInsert-----------------------------
        public int EventInsert(int id_ce, string title, String start_date, String end_date, string content)
        {
            Collection<SqlParameter> parameterList = new Collection<SqlParameter>();

            parameterList.Add(new SqlParameter("@id_ce", id_ce));
            parameterList.Add(new SqlParameter("@title", title));
            parameterList.Add(new SqlParameter("@start_date", start_date));
            parameterList.Add(new SqlParameter("@end_date", end_date));
            parameterList.Add(new SqlParameter("@content", content));

            int i = SQLHelper.ExecuteNonQuery("spEventInsert", parameterList);

            return i;
        }

        //---------------------EventUpdate-----------------------------
        public int EventUpdate(int id, int id_ce, string title, String start_date, String end_date, string content)
        {
            Collection<SqlParameter> parameterList = new Collection<SqlParameter>();

            parameterList.Add(new SqlParameter("@id", id));
            parameterList.Add(new SqlParameter("@id_ce", id_ce));
            parameterList.Add(new SqlParameter("@title", title));
            parameterList.Add(new SqlParameter("@start_date", start_date));
            parameterList.Add(new SqlParameter("@end_date", end_date));
            parameterList.Add(new SqlParameter("@content", content));

            int i = SQLHelper.ExecuteNonQuery("spEventUpdate", parameterList);

            return i;
        }

        //---------------------EventDelete-----------------------------
        public int EventDelete(int id)
        {
            Collection<SqlParameter> parameterList = new Collection<SqlParameter>();

            parameterList.Add(new SqlParameter("@id", id));

            int i = SQLHelper.ExecuteNonQuery("spEventDelete", parameterList);

            return i;
        }
    }
}
